<?php
/**
 * 收藏
 *
 * @copyright  Copyright (c) 2015-2025 NcPHP Inc. (http://www.ncphp.com)
 * @license    http://www.ncphp.com
 * @link       http://www.ncphp.com
 * @author	   NcPHP Team
 * @since      File available since Release v1.1
 */
defined('InNcPHP') or exit('Access Invalid!');

class collectModel extends Model{

	public function __construct(){
		parent::__construct('collect');
	}

    /**
     * 分页查询收藏列表
     * @param int $member_id
     * @param int $cate1
     * @param int $page
     * @return mixed
     */
    public function getCollectListPage($member_id, $cate1, $page = 10){
        $tables = 'collect,ticket';
        $fields = implode(',', array(
            'collect.ticket_id',
            'collect.add_time',
            'ticket.tk_id',
            'ticket.tk_title',
            'ticket.tk_subtitle',
            'ticket.tk_thumb',
            'ticket.tk_show_price',
            'ticket.tk_city_name',
            'ticket.tk_cate1',
            'ticket.tk_cate2',
            'ticket.tk_status',
            'ticket.tk_market_price',
        ));
        $on = 'collect.ticket_id=ticket.tk_id';
        $condition = array('collect.member_id'=>$member_id, 'collect.cate1'=>$cate1);

        return $this->table($tables)
            ->field($fields)
            ->join('left')
            ->on($on)
            ->where($condition)
            ->page($page)
            ->order('collect.add_time desc')
            ->select();
    }

    /**
     * 获取收藏信息
     * @param array $condition
     * @param string $field
     * @return mixed
     */
    public function getCollectInfo($condition, $field = '*')
    {
        return $this->table('collect')->field($field)->where($condition)->find();
    }

    /**
     * 添加收藏
     * @param array $params
     * @return mixed
     */
    public function addCollect($params)
    {
        return $this->table('collect')->insert($params);
    }

    /**
     * 取消收藏
     * @param array $condition
     * @return mixed
     */
    public function delCollect($condition = array())
    {
        return $this->table('collect')->where($condition)->delete();
    }
}
?>